home *** CD-ROM | disk | FTP | other *** search
- $$Message Main, mm:mmMain$Prototype.name$.cp
- $$File mm:mmMain$Prototype.name$.cp
- /* mmMain$Prototype.name$ */
-
- /*
- Program name: mmMain$Prototype.name$
- Function: This is the main module for this program.
- History: $Date$ Original by $Author$
-
- */
-
- #include "mmCommon$Prototype.name$.h" /* Common */
- #include "Common$Prototype.name$.h" /* Common */
-
-
- Boolean DoIt; /* Flag saying an event is ready */
- short code; /* Determine event type */
- WindowPtr whichWindow; /* See which window for event */
- long mResult; /* Menu list and item selected values */
- short theMenu,theItem; /* Menu list and item selected */
- Boolean Is_A_Dialog; /* Flag for modless dialogs */
- short charCode, itemHit; /* For modeless dialogs*/
- char ch; /* Key pressed in Ascii */
- Boolean DoTheModelessEvent, CmdDown; /* For modeless dialogs*/
- WindowPeek thePeeked; /* For modeless dialogs*/
-
-
- /* MAIN entry point */
- void main(void);
-
- /* ======================================================= */
- /* ======================================================= */
-
- /* Routine: WNEIsImplemented */
- /* Purpose: See if the MultiFinder trap, WaitNextEvent, is available */
-
- Boolean CmmApplication::IsWNEIsImplemented() /* See if WaitNextEvent is available */
- {
- #define WNETrapNumber 0xA860 /* The expected trap number */
- #define kGestaltTrapID 0xA1AD /* The expected trap number */
-
- SysEnvRec theWorld; /* Environment record */
- OSErr discardError; /* Error code returned */
- Boolean theWNEIsImplemented; /* Value to return */
- long result; /* Value returned */
-
-
- Black_ForeColor.red = 0x0000; Black_ForeColor.green = 0x0000; Black_ForeColor.blue = 0x0000; /* Get black color */
- White_BackColor.red = 0xFFFF; White_BackColor.green = 0xFFFF; White_BackColor.blue = 0xFFFF; /* Get white color */
-
- Has.ColorQD = FALSE; /* Init to no color QuickDraw */
- Has.FPU = FALSE; /* Init to no floating point chip */
- Has.AppleEvents = FALSE; /* Whether AppleEvents are available */
- Has.AliasMgr = FALSE; /* Whether AliasMgr is available */
- Has.EditionMgr = FALSE; /* Whether EditionMgr is available */
- Has.Gestalt = FALSE; /* Whether Gestalt is available */
- Has.NewStdFile = FALSE; /* Whether NewStdFile is available */
- Has.PPCToolbox = FALSE; /* Whether PPCToolbox is available */
- Has.QuickDraw32Bit = FALSE; /* Whether 32Bit QuickDraw is available */
- InTheForeground = TRUE; /* Init to a foreground app */
-
- discardError = SysEnvirons(1, &theWorld); /* Check how old this system is */
- if (theWorld.machineType < 0) /* Negative means really old */
- {
- theWNEIsImplemented = FALSE; /* Really old ROMs, no WNE possible */
- }
- else
- {
- theWNEIsImplemented = true;
- Has.ColorQD = theWorld.hasColorQD; /* Flag for Color QuickDraw being available */
- Has.FPU = theWorld.hasFPU; /* Flag for Floating Point Math Chip being available */
- Has.Gestalt = true;
- if (Has.Gestalt) /* Do if Gestalt is available */
- {
- discardError = Gestalt(gestaltAliasMgrAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltAliasMgrPresent)) != 0))
- Has.AliasMgr = TRUE;
-
- discardError = Gestalt(gestaltEditionMgrAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltEditionMgrPresent)) != 0))
- Has.EditionMgr = TRUE;
-
- discardError = Gestalt(gestaltAppleEventsAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltAppleEventsPresent)) != 0))
- Has.AppleEvents = TRUE;
-
- discardError = Gestalt(gestaltPPCToolboxAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltPPCToolboxPresent)) != 0))
- Has.PPCToolbox = TRUE;
-
- discardError = Gestalt(gestaltQuickdrawVersion,&result);
- if ((discardError == 0) && ((result & gestalt32BitQD) != 0))
- Has.QuickDraw32Bit = TRUE;
-
- discardError = Gestalt(gestaltStandardFileAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltStandardFile58)) != 0))
- Has.NewStdFile = TRUE;
- }
- }
-
- return(theWNEIsImplemented);
- }
-
- /* ======================================================= */
-
- /* Routine: DoOSEvent */
- /* Purpose: Handle DoOSEvents */
-
- void CmmApplication::DoOSEvent(EventRecord *myEvent)
- {
-
-
- if (((myEvent->message & osEvtMessageMask) >> 24) == suspendResumeMessage) /* See which */
- {
- if ((myEvent->message & resumeFlag) == 0) /* Suspend */
- InTheForeground = FALSE;
- else
- InTheForeground = TRUE;
- }
- }
-
- /* ======================================================= */
-
- void CmmApplication::Handle_Extra_User_Event(UserEventPRec theUserEvent) /* Hook, to handle user events */
- {
- /* Expected to be overridden by the user code */
- }
-
- /* ======================================================= */
-
- /* Routine: Handle_User_Event */
- /* Purpose: Check for user events */
-
- void CmmApplication::Handle_User_Event() /* Check for user events */
- {
- UserEventRec TheUserEvent; /* The user event */
-
-
- GetUserEvent(&TheUserEvent); /* Check for any user events */
- if (TheUserEvent.ID != UserEvent_None) /* Only do if we have any */
- {
-
- switch (TheUserEvent.ID) /* Key off the Event ID */
- {
- case UserEvent_Open_Window: /* Open a Window or Modeless dialog */
- switch (TheUserEvent.ID2) /* Do the appropiate window */
- {
- $$Loop Alerts
- case ResA_$Worksheet.name$:
- g$Worksheet.name$->BringUpAlert(); /* Open this alert */
- break;
- $$EndLoop
- $$Loop ModalDialogs
- case ResD_$Worksheet.name$:
- g$Worksheet.name$->BringUpDialog(); /* Open this modal dialog */
- break;
- $$EndLoop
- $$Loop ModelessDialogs
- case ResD_$Worksheet.name$:
- g$Worksheet.name$->Open(); /* Open this modeless dialog */
- break;
- $$EndLoop
- $$Loop Windows
- case ResW_$Worksheet.name$:
- g$Worksheet.name$->Open(); /* Open this window */
- break;
- $$EndLoop
- default: /* Handle others */
- break;
- } /* End of the switch */
- break;
-
- case UserEvent_Close_Window: /* Close a Window or Modeless dialog */
- switch (TheUserEvent.ID2) { /* Do the appropiate window */
- $$Loop ModelessDialogs
- case ResD_$Worksheet.name$:
- g$Worksheet.name$->Close(g$Worksheet.name$->theWindow);/* Close this modeless dialog */
- break;
- $$EndLoop
- $$Loop Windows
- case ResW_$Worksheet.name$:
- g$Worksheet.name$->Close((WindowPtr)-1); /* Close this window */
- break;
- $$EndLoop
- default: /* Handle others */
- break;
- } /* End of the switch */
- break;
-
- default: /* Not standard, must be program specific */
- break;
- } /* End of switch */
- }
- }
-
- /* ======================================================= */
-
- /* Routine: DoKeyEvent */
- /* Purpose: Handle a key pressed */
-
- void CmmApplication::DoKeyEvent(EventRecord *myEvent) /* Handle key presses */
- {
- short charCode; /* Key code */
- char ch; /* Key pressed in Ascii */
- long mResult; /* Menu list and item, if a command key */
- short theMenu,theItem; /* Menu list and item, if command key */
-
-
- charCode = myEvent->message & charCodeMask; /* Get the character */
- ch = (char)charCode; /* Change it to ASCII */
-
- if ((myEvent->modifiers & cmdKey) != 0) /* See if Command key is down */
- {
- gMenus->EnableTheMenus(); /* Let us in to enable and disable menus*/
- mResult = MenuKey(ch); /* See if a menu selection */
- theMenu = HiWord(mResult); /* Get the menu list number */
- theItem = LoWord(mResult); /* Get the menu item number */
- if (theMenu != 0) /* See if a list was selected */
- gMenus->HandleMenuSelection(theMenu,theItem); /* Do the menu selection */
-
- if (((ch == 'x') || (ch == 'X')) && (theInput != NIL))
- TECut(theInput); /* Handle a Cut in a TE area */
- if (((ch == 'c') || (ch == 'C')) && (theInput != NIL))
- TECopy(theInput); /* Handle a Copy in a TE area */
- if (((ch == 'v') || (ch == 'V')) && (theInput != NIL))
- TEPaste(theInput); /* Handle a Paste in a TE area */
- }
- else if (theInput != NIL)
- TEKey(ch,theInput); /* Place the normal key stroke */
- }
-
- /* ======================================================= */
-
- /* Routine: DoDiskEvent */
- /* Purpose: Handle a diskette inserted */
-
- void CmmApplication::DoDiskEvent(EventRecord *myEvent) /* Handle disk inserted */
- {
- short theError; /* Error returned from mount */
-
-
- if (HiWord(myEvent->message) != noErr) /* See if a diskette mount error */
- {
- myEvent->where.h = ((screenRect.bounds.right - screenRect.bounds.left) / 2) - (304 / 2);/* Center horz */
- myEvent->where.v = ((screenRect.bounds.bottom - screenRect.bounds.top) / 3) - (104 / 2);/* Top 3ed vertically */
- InitCursor(); /* Make sure it has an arrow cursor */
- theError = DIBadMount(myEvent->where, myEvent->message);/* Let the OS handle the diskette */
- }
- }
-
- /* ======================================================= */
-
- /* Routine: DoZoom */
- /* Purpose: Handle a window zoom */
-
- Boolean CmmApplication::DoZoom(WindowPtr whichWindow,short code,EventRecord *myEvent)/* Handle a window zoom */
- {
- Rect OldRect; /* Window rect before the zoom */
- Point myPt; /* Point for tracking zoom box */
- long theRefCon; /* Refcon with layer masked off */
- Boolean HandledEvent;
-
-
- HandledEvent = false;
- if (!Doing_MovableModal) /* Select proper window */
- {
- if (whichWindow != NIL) /* See if we have a legal window */
- {
- SetPort(whichWindow); /* Get ready to draw in this window */
-
- myPt = myEvent->where; /* Get mouse position */
- GlobalToLocal(&myPt); /* Make it relative */
-
- OldRect = whichWindow->portRect; /* Save the rect before resizing */
-
- if (TrackBox(whichWindow, myPt, code)) /* Zoom it */
- {
- ZoomWindow(whichWindow, code, TRUE); /* Resize to result */
- EraseRect(&whichWindow->portRect); /* Make sure we update the whole window effectively */
- InvalRect(&whichWindow->portRect); /* Tell ourselves to update, redraw, the window contents */
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- HandledEvent = true;
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- $$if Window.Zoomable
- case ResW_$Worksheet.name$:
- g$Worksheet.name$->Resized(&OldRect, whichWindow); /* Resized this window */
- break;
- $$endif
- $$EndLoop
-
- default: /* Handle others */
- HandledEvent = false;
- break;
- }
- Mk_HiliteWindow(whichWindow); /* Hilite it again */
- }
- }
- }
- return(HandledEvent);
- }
-
- /* ======================================================= */
-
- /* Routine: DoGrow */
- /* Purpose: Handle a window resize */
-
- Boolean CmmApplication::DoGrow(WindowPtr whichWindow,EventRecord *myEvent)
- {
- Rect OldRect; /* Window rect before the grow */
- Point myPt; /* Point for tracking grow box */
- Rect GrowRect; /* Set the grow bounds */
- long mResult; /* Result from the grow */
- long theRefCon; /* Refcon with layer masked off */
- Boolean HandledEvent;
-
-
- HandledEvent = false;
- if (!Doing_MovableModal) /* Select proper window */
- {
- if (whichWindow != nil) /* See if we have a legal window */
- {
- SetPort(whichWindow); /* Get ready to draw in this window */
-
- myPt = myEvent->where; /* Get mouse position */
- GlobalToLocal(&myPt); /* Make it relative */
-
- OldRect = whichWindow->portRect; /* Save the rect before resizing */
-
- SetRect(&GrowRect, 24, 4,4096L, 4096L);/* l,t,r,b */
- mResult = GrowWindow(whichWindow, myEvent->where, &GrowRect);/* Grow it */
- SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), true);/* Resize to result */
-
- HandledEvent = true;
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
-
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- $$if Window.Resizable
- case ResW_$Worksheet.name$:
- g$Worksheet.name$->Resized(&OldRect, whichWindow); /* Resized this window */
- break;
- $$endif
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- HandledEvent = false;
- break; /* end of otherwise */
- } /* end of switch */
-
- SetPort(whichWindow); /* Get ready to draw in this window */
-
- myPt.h = whichWindow->portRect.right - whichWindow->portRect.left;/* Local right edge */
- myPt.v = whichWindow->portRect.bottom - whichWindow->portRect.top;/* Local bottom edge */
-
- SetRect(&GrowRect, 0, OldRect.bottom - 15, OldRect.right + 15, OldRect.bottom + 15);/* Position for horz scrollbar area */
- EraseRect(&GrowRect); /* Erase old area */
- InvalRect(&GrowRect); /* Flag us to update it */
-
- SetRect(&GrowRect, OldRect.right - 15, 0, OldRect.right + 15, OldRect.bottom + 15);/* Position for vert scrollbar area */
- EraseRect(&GrowRect); /* Erase old area */
- InvalRect(&GrowRect); /* Flag us to update it */
-
- DrawGrowIcon(whichWindow); /* Draw the grow Icon again */
- }
- }
- return(HandledEvent);
- }
-
- /* ======================================================= */
-
- /* Routine: DoDrag */
- /* Purpose: Drag a window around */
-
- Boolean CmmApplication::DoDrag(WindowPtr whichWindow,EventRecord *myEvent)
- {
- Rect OldRect; /* Window rect before the drag */
- Rect tempRect; /* temporary rect */
- long theRefCon; /* Refcon with layer masked off */
- Boolean HandledEvent;
-
-
- HandledEvent = false;
- if ((!Doing_MovableModal) || (Doing_MovableModal && (whichWindow == FrontWindow())))/* See if OK to drag */
- {
- OldRect = whichWindow->portRect; /* Save the rect before resizing */
-
- if (!Doing_MovableModal) /* Select proper window */
- Mk_HiliteWindow(whichWindow);
- SetRect(&tempRect, -32000, -32000, 32000, 32000);
- Mk_DragWindow(whichWindow, myEvent->where, tempRect);/* Drag the window */
-
- HandledEvent = true;
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop ModelessDialogs
- case ResD_$Worksheet.name$:
- g$Worksheet.name$->Moved(&OldRect, whichWindow); /* Moved this modeless dialog */
- break;
- $$EndLoop
- $$Loop Windows
- case ResW_$Worksheet.name$:
- g$Worksheet.name$->Moved(&OldRect, whichWindow); /* Moved this window */
- break;
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- HandledEvent = false;
- break; /* end of otherwise */
- } /* end of switch */
- }
- return(HandledEvent);
- }
-
- /* ======================================================= */
-
- /* Routine: DoGoAway */
- /* Purpose: Close a window */
-
- Boolean CmmApplication::DoGoAway(WindowPtr whichWindow,EventRecord *myEvent)
- {
- long theRefCon; /* Refcon with layer masked off */
- Boolean HandledEvent;
-
-
- HandledEvent = false;
- if (!Doing_MovableModal) /* Select proper window */
- {
- if (TrackGoAway(whichWindow,myEvent->where)) /* See if mouse released in GoAway box */
- {
- HandledEvent = true;
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop ModelessDialogs
- $$if ModelessDialog.GoAway
- case ResD_$Worksheet.name$:
- g$Worksheet.name$->Close(whichWindow); /* Close this modeless dialog */
- break;
- $$endif
- $$EndLoop
- $$Loop Windows
- $$if Window.GoAway
- case ResW_$Worksheet.name$:
- g$Worksheet.name$->Close(whichWindow); /* Close this window */
- break;
- $$endif
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- HandledEvent = false;
- break; /* end of otherwise */
- } /* end of switch */
- }
- }
- return(HandledEvent);
- }
-
- /* ======================================================= */
-
- /* Routine: DoInContent */
- /* Purpose: Pressed in the content area */
-
- Boolean CmmApplication::DoInContent(WindowPtr whichWindow,EventRecord *myEvent)
- {
- long theRefCon; /* Refcon with layer masked off */
- Boolean HandledEvent;
-
-
- HandledEvent = false;
- if (!Doing_MovableModal) /* Select proper window */
- {
- if (Mk_Is_FrontWindow(whichWindow) == false) /* See if already selected or not, in front if selected */
- Mk_HiliteWindow(whichWindow);
- else
- {
- SetPort(whichWindow); /* Get ready to draw in this window */
- Mk_HiliteWindow(whichWindow);
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- HandledEvent = true;
-
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- case ResW_$Worksheet.name$:
- g$Worksheet.name$->HandleEvent(myEvent); /* Handle this window */
- break;
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- HandledEvent = false;
- break; /* end of otherwise */
- } /* end of switch */
- }
- }
- return(HandledEvent);
- }
-
- /* ======================================================= */
-
- /* Routine: DoUpdate */
- /* Purpose: Got an update event */
-
- Boolean CmmApplication::DoUpdate(EventRecord *myEvent)
- {
- WindowPtr whichWindow; /* See which window for event */
- long theRefCon; /* Refcon with layer masked off */
- Boolean HandledEvent;
-
-
- whichWindow = (WindowPtr)myEvent->message; /* Get the window the update is for */
- HandledEvent = true;
-
- BeginUpdate(whichWindow); /* Set the clipping to the update area */
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- case ResW_$Worksheet.name$:
- g$Worksheet.name$->Update(whichWindow); /* Update this window */
- break;
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- HandledEvent = false;
- break; /* end of otherwise */
- } /* end of switch */
- EndUpdate(whichWindow); /* Return to normal clipping area */
- return(HandledEvent);
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.DoActivate */
- /* Purpose: Got an activate or deactivate event */
-
- Boolean CmmApplication::DoActivate(EventRecord *myEvent)
- {
- WindowPtr whichWindow; /* See which window for event */
- Boolean Do_An_Activate; /* Flag to pass */
- Boolean HandledEvent;
- long theRefCon; /* Refcon with layer masked off */
-
-
- whichWindow = (WindowPtr)myEvent->message; /* Get the window the update is for */
- HandledEvent = true;
-
- Do_An_Activate = ((myEvent->modifiers & 0x0001) != 0);/* Make sure it is Activate and not DeActivate */
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- case ResW_$Worksheet.name$:
- g$Worksheet.name$->Activate(whichWindow,Do_An_Activate); /* Activate or deactivate this window */
- break;
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- HandledEvent = false;
- break; /* end of otherwise */
- } /* end of switch */
- return(HandledEvent);
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.DoHighLevelEvent */
- /* Purpose: Got a High Level event */
-
- void CmmApplication::DoHighLevelEvent(EventRecord *myEvent)
- {
- OSErr err; /* Error */
-
-
- err = AEProcessAppleEvent(myEvent); /* Go to the processor of apple events */
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.InitExtras */
- /* Purpose: Extra Initialization for the application */
-
- void CmmApplication::InitExtras()
- {
- /* Expected to be overridden by the user code */
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.OpenSplashWindow */
- /* Purpose: Open spash or personalization window */
-
- void CmmApplication::OpenSplashWindow()
- {
- /* Expected to be overridden by the user code */
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.CloseSplashWindow */
- /* Purpose: Close spash or personalization window */
-
- void CmmApplication::CloseSplashWindow()
- {
- /* Expected to be overridden by the user code */
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.Init */
- /* Purpose: Initialize the application */
-
- void CmmApplication::Init() /* Initialize the application */
- {
-
-
- MoreMasters(); /* This reserves space for more handles */
- MaxApplZone(); /* Give us room for memory allocation */
- InitGraf(&QDPort); /* Quickdraw Init */
- InitFonts(); /* Font manager init */
- InitWindows(); /* Window manager init */
- InitMenus(); /* Menu manager init */
- TEInit(); /* Text edit init */
- InitDialogs(nil); /* Dialog manager */
-
- FlushEvents(everyEvent,0); /* Clear out all events */
- InitCursor(); /* Make an arrow cursor */
-
- doneFlag = FALSE; /* Do not exit program yet */
-
- gMenus = new CMenus; /* Allocate the menu handler object */
- gMenus->Init(); /* Init the object and the menu bar */
-
- gPreferences = new CPreferences; /* Allocate the preferences object */
- gPreferences->Init(); /* Init the object */
-
- gFiles = new CFiles; /* Allocate the file handler object */
- gFiles->Init(); /* Init the object */
-
- gPrinting = new CPrinting; /* Allocate the printing handler object */
- gPrinting->Init(); /* Init the object */
-
- this->OpenSplashWindow(); /* Open spash or personalization window */
-
- theInput = nil; /* Init to no text edit selection active */
-
- SleepValue = 40; /* Set sleep value */
- WNE = this->IsWNEIsImplemented(); /* See if WaitNextEvent is available */
-
- UserEventList = nil; /* No user events yet */
-
- cursorRgn = NewRgn(); /* Cursor region for WaitNextEvent */
-
- if (Has.AppleEvents) /* See if AppleEvents are available */
- InitAppleEvents(); /* Initialize for AppleEvents */
-
- gCurrentAlert = nil;
- $$Loop Alerts
- g$Worksheet.name$ = new CA$Worksheet.name$; /* Allocate the alert object */
- g$Worksheet.name$->Init();
- $$EndLoop
- $$Loop ModalDialogs
- g$Worksheet.name$ = new CD$Worksheet.name$; /* Allocate the Modal Dialog object */
- g$Worksheet.name$->Init();
- $$EndLoop
- $$Loop ModelessDialogs
- g$Worksheet.name$ = new CMD$Worksheet.name$; /* Allocate the Modeless Dialog object */
- g$Worksheet.name$->Init();
- $$EndLoop
- $$Loop Windows
- g$Worksheet.name$ = new CW$Worksheet.name$; /* Allocate the window object */
- g$Worksheet.name$->Init(); /* Initialize Window, $Worksheet.FullName$ */
- $$EndLoop
-
- Mk_ClearLayers(); /* Init layer array */
- Doing_MovableModal = false; /* Not currently doing a movable modal */
-
- this->InitExtras(); /* HOOK, Do extra user initialization */
-
- gPreferences->GetPreferences(); /* Get preferences */
-
- $$Loop Alerts
- $$if Worksheet.OpenAtStartup
- g$Worksheet.name$->BringUpAlert(); /* Open at program start, $Worksheet.FullName$ */
- $$endif
- $$EndLoop
- $$Loop ModalDialogs
- $$if Worksheet.OpenAtStartup
- g$Worksheet.name$->BringUpDialog(); /* Open at program start, $Worksheet.FullName$ */
- $$endif
- $$EndLoop
- $$Loop ModelessDialogs
- $$if Worksheet.OpenAtStartup
- g$Worksheet.name$->Open(); /* Open at program start, $Worksheet.FullName$ */
- $$endif
- $$EndLoop
- $$Loop Windows
- $$if Worksheet.OpenAtStartup
- g$Worksheet.name$->Open(); /* Open at program start, $Worksheet.FullName$ */
- $$endif
- $$EndLoop
-
- this->CloseSplashWindow(); /* Close spash or personalization window */
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.TopOfLoop */
- /* Purpose: HOOK at top of main event loop */
-
- void CmmApplication::TopOfLoop()
- {
- /* Expected to be overridden by the user code */
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.FilterEvent */
- /* Purpose: HOOK, Allow user to filter all events before the main loop handles them */
- /* Set DoIt to TRUE to let the main loop handle the event. */
-
- void CmmApplication::FilterEvent(Boolean *DoIt, EventRecord *myEvent)
- {
-
-
- *DoIt = TRUE; /* Let the main loop handle it */
- if (myEvent->what == 0) /* Handle a NULL event*/
- *DoIt = FALSE; /* ...Tell the main loop to skip it*/
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.InitAppleEvents */
- /* Purpose: Init AppleEvent handlers. */
-
- void CmmApplication::InitAppleEvents(void)
- {
- OSErr err; /* Error */
- AEEventHandlerUPP theRoutine;
-
-
- theRoutine = NewAEEventHandlerProc(DispatchAppleEvent);
- err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,
- theRoutine,kAEOpenApplication,false);
- err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
- theRoutine,kAEOpenDocuments,false);
- err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
- theRoutine,kAEPrintDocuments,false);
- err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
- theRoutine,kAEQuitApplication,false);
-
- //err = AEObjectInit(); /* Init the AE Object code */
-
- gSelfPSN.highLongOfPSN = 0; /* Init to the current process ID */
- gSelfPSN.lowLongOfPSN = kCurrentProcess;
- err = AECreateDesc(typeProcessSerialNumber,(Ptr)&gSelfPSN,sizeof(ProcessSerialNumber),&gSelfAddress);
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.Run */
- /* Purpose: Run the application */
-
- void CmmApplication::Run() /* Run the application */
- {
- Boolean HandledEvent;
-
-
- do
- {
- this->TopOfLoop(); /* HOOK at top of main event loop */
-
- this->Handle_User_Event(); /* Check for user events */
-
- if (theInput != NIL) /* See if a TE is active */
- TEIdle(theInput); /* Blink the cursor if everything is ok */
-
- if (WNE) /* See if do the MultiFinder way */
- DoIt = WaitNextEvent(everyEvent, &myEvent, SleepValue, cursorRgn);/* Wait for an event */
- else
- {
- SystemTask(); /* For support of desk accessories */
- DoIt = GetNextEvent(everyEvent, &myEvent); /* See if an event is ready */
- }
-
- this->FilterEvent(&DoIt,&myEvent); /* HOOK, Let us at the event first */
-
- if (DoIt) /* If event then... */
- {
- Is_A_Dialog = IsDialogEvent(&myEvent); /* See if a modeless dialog event */
- if (Is_A_Dialog) /* Handle a dialog event */
- {
- if (myEvent.what == updateEvt) /* Handle the update of a Modeless Dialog */
- {
- whichWindow = (WindowPtr)myEvent.message; /* Get the window the update is for */
- BeginUpdate(whichWindow); /* Set update clipping area */
- $$Loop ModelessDialogs
- g$Worksheet.name$->Update(whichWindow); /* Update Modeless Dialog, $Worksheet.FullName$ */
- $$EndLoop
- EndUpdate(whichWindow); /* Return to normal clipping area */
- }
- else
- {
- DoTheModelessEvent = TRUE; /* Go ahead and do it so far */
-
- if (myEvent.what == keyDown) /* Check the key down, for a command key event */
- {
- CmdDown = ((myEvent.modifiers / cmdKey) & 1);/* Get the command key state */
- charCode = myEvent.message & charCodeMask;/* Get the character */
- ch = (char)charCode; /* Change it to ASCII */
-
- if ((charCode == 13) || (charCode == 0x03))/* CR or Enter */
- DoTheModelessEvent = TRUE; /* Handle the default selection */
-
- if (CmdDown != 0) /* Handle if the command key was down */
- {
- gMenus->EnableTheMenus(); /* Let us in to enable and disable menus*/
- mResult = MenuKey(ch); /* See if a menu selection */
- theMenu = HiWord(mResult); /* Get the menu list number */
- theItem = LoWord(mResult); /* Get the menu item number */
- if (theMenu != 0) /* See if a list was selected */
- gMenus->HandleMenuSelection(theMenu,theItem); /* Do the menu selection */
-
- whichWindow = FrontWindow(); /* Get the front window */
- if ((ch == 'x') || (ch == 'X')) /* Handle a CUT */
- DlgCut(whichWindow);
- if ((ch == 'c') || (ch == 'C')) /* Handle a COPY */
- DlgCopy(whichWindow);
- if ((ch == 'v') || (ch == 'V')) /* Handle a PASTE */
- DlgPaste(whichWindow);
-
- DoTheModelessEvent = FALSE;/* We handled the command key */
- }
- }
-
- if (DoTheModelessEvent) /* Do we handle it? */
- {
- if ((DialogSelect(&myEvent, &whichWindow, &itemHit)) || (myEvent.what == mouseDown) || (myEvent.what == keyDown)) /* Ck if do it */
- {
- $$Loop ModelessDialogs
- g$Worksheet.name$->HandleEvent(&myEvent,whichWindow,itemHit); /* Handle the Modeless Dialog, $Worksheet.FullName$ */
- $$EndLoop
- }
- }
- }
- }
- else
- {
-
- switch (myEvent.what) /* Decide type of event */
- {
- case mouseDown : /* Mouse button pressed */
- code = FindWindow(myEvent.where, &whichWindow);/* Get which window the event happened in */
-
- switch (code) /* Decide type of event again */
- {
- case inMenuBar : /* In the menubar */
- gMenus->EnableTheMenus(); /* Let us in to enable and disable menus*/
- mResult = MenuSelect(myEvent.where);/* Do menu selection */
- theMenu = HiWord(mResult); /* Get the menu list number */
- theItem = LoWord(mResult); /* Get the menu list item number */
- gMenus->HandleMenuSelection(theMenu,theItem); /* Do the menu selection */
- break;
-
- case inDrag : /* In window drag area */
- HandledEvent = this->DoDrag(whichWindow,&myEvent);
- break;
-
- case inGrow : /* In window grow area */
- HandledEvent = this->DoGrow(whichWindow,&myEvent);
- break;
-
- case inZoomIn : /* In window zoom area */
- case inZoomOut :
- HandledEvent = this->DoZoom(whichWindow,code,&myEvent);
- break;
-
- case inGoAway : /* In window goaway area */
- HandledEvent = this->DoGoAway(whichWindow,&myEvent);
- break;
-
- case inContent : /* In window contents */
- HandledEvent = this->DoInContent(whichWindow,&myEvent);
- break;
-
- case inSysWindow : /* See if a DA selection */
- SystemClick(&myEvent, whichWindow); /* Let other programs in */
- break;
-
- default: /* Handle others */
- break; /* End of otherwise */
- } /* End of code case */
- break; /* End of MouseDown */
-
- case keyDown: /* Handle key inputs */
- case autoKey: /* and auto repeats */
- this->DoKeyEvent(&myEvent);
- break;
-
- case updateEvt : /* Update event for a window */
- HandledEvent = this->DoUpdate(&myEvent);
- break;
-
- case diskEvt : /* Disk inserted event */
- this->DoDiskEvent(&myEvent);
- break;
-
- case activateEvt : /* Window activated event */
- HandledEvent = this->DoActivate(&myEvent);
- break;
-
- case osEvt: /* OS event */
- this->DoOSEvent(&myEvent);
- break;
-
- case kHighLevelEvent: /* High Level event */
- if (Has.AppleEvents) /* See if has Apple Events */
- this->DoHighLevelEvent(&myEvent); /* Do AppleEvents */
- break;
-
- default: /* Used for debugging, to see what other events are coming in */
- break; /* End of otherwise */
-
- } /* End of case */
-
- }
- }
- else
- {
- whichWindow = FrontWindow(); /* Get the current front window */
- if (whichWindow != NIL) /* See if we have a window */
- {
- thePeeked = (WindowPeek)whichWindow; /* Peek inside, look for dialog */
- if (thePeeked->windowKind == dialogKind) /* DialogSelect will crash if no dialogs */
- {
- if (DialogSelect(&myEvent, &whichWindow, &itemHit))/* Blink cursor in modeless TEs */
- {
- }
- }
- }
- }
- } /* end of while */
- while (!doneFlag); /* End of the event loop */
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.ExitExtras */
- /* Purpose: Exit the application */
-
- void CmmApplication::ExitExtras() /* Exit the application */
- {
- /* Expected to be overridden by the user code */
- }
-
- /* ======================================================= */
-
- /* Routine: CmmApplication.Exit */
- /* Purpose: Exit the application */
-
- void CmmApplication::Exit() /* Exit the application */
- {
-
-
- $$Loop ModelessDialogs
- g$Worksheet.name$->Close(g$Worksheet.name$->theWindow); /* Close this modeless dialog */
- $$EndLoop
- $$Loop Windows
- g$Worksheet.name$->Close((WindowPtr)-1); /* Close this window */
- $$EndLoop
-
- gPreferences->SetPreferences(); /* Set default preferences */
-
- $$Loop Alerts
- delete g$Worksheet.name$; /* Deallocate the alert object */
- $$EndLoop
- $$Loop ModalDialogs
- delete g$Worksheet.name$; /* Deallocate the Modal object */
- $$EndLoop
- $$Loop ModelessDialogs
- delete g$Worksheet.name$; /* Deallocate the Modeless object */
- $$EndLoop
- $$Loop Windows
- delete g$Worksheet.name$; /* Deallocate the window object */
- $$EndLoop
- ExitExtras(); /* HOOK, Do extra user exit code */
- }
-
- /* ======================================================= */
- /* ======================================================= */
-
- void main() /* Start of main body */
- {
-
-
- gApplication = new CApplication; /* Allocate the application object */
-
- gApplication->Init(); /* Init the object and the application */
-
- gApplication->Run(); /* Run the application */
-
- gApplication->Exit(); /* Exit the application */
-
- } /* end of main */
- $$CloseFile
-
-